package com.v.im.websocketservice.kafkaconsumer.listener;

import com.v.im.commonmodule.utils.chat.Message;
import com.v.im.commonmodule.utils.kafka.KafkaTopic;
import com.v.im.websocketservice.service.PushClientService;
import com.v.im.websocketservice.service.WebSocketService;
import com.v.im.websocketservice.websocket.ImWebSocket;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Log
@Component
public class ImListener {


    /**
     *  单聊消费者
     *
     * @param record
     * @param message
     * @throws IOException
     */
    @KafkaListener(topics = {"${kafka.topic}"})
    public void sendFriendMessage(ConsumerRecord<?, ?> record, Message message) throws IOException {
        log.info("kafka收到单聊消息");
        PushClientService.sendFriendMessag1e(message);
    }

    /**
     *  群聊消费者
     *
     * @param record
     * @param message
     * @throws IOException
     */

//    @KafkaListener(topics = KafkaTopic.CROWD_TOPIC)
//    public void sendCrowdMessage(ConsumerRecord<?, ?> record, Message message) throws IOException {
//        System.out.println("kafka收到群聊消息");
//        ImWebSocket.sendCrowdMessage(message);
//    }

}
